﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;
using ElingOA6_Admin_DSJCJ.Models;
using System.Data;
using DevExpress.Web.Mvc;
using DevExpress.Web.ASPxUploadControl;
using Newtonsoft.Json;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 人员管理
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class EmplController : AdminBaseController
    {
        /// <summary>
        ///人员管理
        /// </summary>
        /// <returns>人员管理主页面</returns>
        [AuthorityActionFilter("m_HRPerson", Order = 1)]
        [LogPageActionFilter("人员管理", Order = 2)]
        public ActionResult Index()
        {
            if (null != Fetch.Get("content"))
            {
                ViewData["content"] = Fetch.Get("content");
            }

            return View();
        }


        /// <summary>
        /// 人员结构树
        /// </summary>
        /// <returns>返回人员树视图</returns>
        public ActionResult EmplTree()
        {
            BLL.HRDept deptBll = new BLL.HRDept();
            TreeModelList treeModelList = new TreeModelList();

            TreeItemModel treeRootItemModel = new TreeItemModel(null)
            {
                Id = "EmplList",
                Name = "人员结构",
                ImageUrl = Url.Content("~/Content/ControlImages/users.png")
            };

            List<Model.HRDept> deptAllList = new List<Model.HRDept>();
            deptAllList = deptBll.GetListByEntityNo(GlobalConstant.ENTITYNO);

            List<Model.HRDept> deptList = deptAllList.Where(c => c.FParentDeptNo == null).ToList();
            if (deptList.Count > 0)
            {
                foreach (Model.HRDept dept in deptList)
                {
                    TreeItemModel treeParentItemModel = new TreeItemModel(treeRootItemModel)
                    {
                        Id = "EmplList?deptNo=" + dept.FDeptNo,
                        Name = dept.FDeptName,
                        ImageUrl = Url.Content("~/Content/ControlImages/dept_Groups.png")
                    };

                    GetChildDept(treeParentItemModel, deptAllList, dept.FDeptNo);
                    //GetEmpl(dept.FDeptNo, treeParentItemModel);

                }
            }

            treeModelList.Add(treeRootItemModel);

            return View(treeModelList);
        }


        /// <summary>
        /// 递归部门树
        /// </summary>
        /// <param name="treeParentItemModel">父级树节点</param>
        /// <param name="deptAllList">部门集合</param>
        /// <param name="preDeptNo">父级部门编号</param>
        public void GetChildDept(TreeItemModel treeParentItemModel, List<Model.HRDept> deptAllList, string preDeptNo)
        {
            List<Model.HRDept> deptList = deptAllList.Where(c => c.FParentDeptNo == preDeptNo).ToList();
            if (deptList.Count > 0)
            {
                foreach (Model.HRDept dept in deptList)
                {
                    TreeItemModel treeItemModel = new TreeItemModel(treeParentItemModel)
                    {
                        Id = "EmplList?deptNo=" + dept.FDeptNo,
                        Name = dept.FDeptName,
                        ImageUrl = Url.Content("~/Content/ControlImages/dept_Groups.png")
                    };

                    GetChildDept(treeItemModel, deptAllList, dept.FDeptNo);
                    GetEmpl(dept.FDeptNo, treeItemModel);
                }
            }
        }


        /// <summary>
        /// 获取人员数据
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <param name="treeParentItemModel">父级树节点</param>
        private void GetEmpl(string deptNo, TreeItemModel treeParentItemModel)
        {
            BLL.HREmplPosition emplBll = new BLL.HREmplPosition();
            DataSet ds = emplBll.GetDeptEmplList(deptNo, GlobalConstant.ENTITYNO);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                {
                    Id = "EmpContent?empNo=" + row["FEmplNo"].ToString(),
                    Name = row["FEmpName"].ToString(),
                    ImageUrl = Url.Content("~/Content/ControlImages/user_male.png")
                };
            }
        }


        /// <summary>
        /// 人员列表页
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <returns>人员列表视图</returns>
        public ActionResult EmplList(string deptNo, string xm,int id = 1)
        {
            int pageIndex = id;
            ViewData["pageIndex"] = id - 1;

            List<Model.HREmpl> emplList = GetEmplList(deptNo, pageIndex, xm);
            if (xm == null)
            {
                ViewData["QueryName"] = "";
            }
            else
            {
                ViewData["QueryName"] = xm;
            }
            ViewData["deptNo"] = deptNo;
            return View(emplList);
        }


        /// <summary>
        /// 人员列表相关方法
        /// </summary>
        /// <returns>返回人员列表Grid操作后视图</returns>
        public ActionResult EmpListPartial()
        {
            int pageIndex = Request.Params["pageIndex"] == null ? 0 : int.Parse(Request.Params["pageIndex"].ToString());
            int pageCount = Request.Params["PageCount"] == null ? 0 : int.Parse(Request.Params["PageCount"].ToString());
            int pageRowSize = Request.Params["pageRowSize"] == null ? 0 : int.Parse(Request.Params["pageRowSize"].ToString());
            int pageRowCount = Request.Params["pageRowCount"] == null ? 0 : int.Parse(Request.Params["pageRowCount"].ToString());
            string deptNo = Request.Params["deptNo"];
            string QueryName = Request.Params["QueryName"];
            bool isRefreshAll = Request.Params["isRefreshAll"] == null ? false : bool.Parse(Request.Params["isRefreshAll"].ToString());
            string callbackArg = DevExpressHelper.CallbackArgument;
            string command = Request.Params["command"] == null ? "" : Request.Params["command"].ToString();

            if (command == "PAGERONCLICK")
            {
                string[] args = callbackArg.Split(new char[1] { '|' });
                string arg = args[args.Count() - 1];

                switch (arg)
                {
                    case "PBN;":
                        {
                            //下一页
                            pageIndex = pageIndex + 2;
                            break;
                        }
                    case "PBP;":
                        {
                            //上一页
                            //pageIndex = pageIndex;
                            break;
                        }
                    case "PBL;":
                        {
                            //最后一页
                            pageIndex = pageCount;
                            break;
                        }
                    case "PBF;":
                        {
                            //第一页
                            pageIndex = 1;
                            break;
                        }
                    default:
                        {
                            //点击数字页码
                            string tempIndex = arg.Replace("PN", "");
                            tempIndex = tempIndex.Replace(";", "");
                            if (RegExp.IsNumeric(tempIndex))
                            {
                                pageIndex = int.Parse(tempIndex) + 1;
                            }
                            break;
                        }

                }
            }
            else
            {
                if (command == "REFRESH")
                {
                    if (isRefreshAll)
                    {
                        //第一页
                        pageIndex = 1;
                    }
                }
                else
                {
                    pageIndex = pageIndex + 1;
                }
            }

            ViewData["pageIndex"] = pageIndex - 1;

            List<Model.HREmpl> emplList = GetEmplList(deptNo, pageIndex, QueryName, pageRowSize);


            return PartialView("EmpListPartial", emplList);
        }

        /// <summary>
        /// 获取部门人员数据
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageRowSize">每页显示页数</param>
        /// <returns>人员数据集合</returns>
        private List<Model.HREmpl> GetEmplList(string deptNo, int pageIndex, string xm, int pageRowSize = 0)
        {
            if (null != deptNo)
            {
                deptNo = Fetch.estimateString(deptNo, CheckGetEnum.Safety);
            }
            else
            {
                deptNo = string.Empty;
            }

            BLL.HRDept deptBll = new BLL.HRDept();
            string strDepts = deptBll.GetSubDeptNo(deptNo, GlobalConstant.ENTITYNO);
            string where = " FEntityNo='" + GlobalConstant.ENTITYNO + "'";
            if (strDepts != string.Empty)
            {
                where += " and FDeptNo in(" + strDepts + ")";
            }

            where += " and FEmpName like '%" + xm + "%'";
            where += " AND FIsMainPosition='Y'";
            BLL.Common commonBll = new BLL.Common();

            string fiedls = "FEmplNo,FEmpName,FOfficeTel,FMobile,FSex,FDutyNo,FLoginIPAddress";
            int total;
            DataSet ds = commonBll.GetListByPage("v_HREmpl", fiedls, Common.GlobalConstant.CONSTRING_PAGESIZE, pageIndex, where, "FSeq,FDutyNo", 0, out total);

            BLL.HREmpl emplBll = new BLL.HREmpl();
            List<Model.HREmpl> emplAllList = new List<Model.HREmpl>();
            List<Model.HREmpl> emplList = emplBll.DataTableToListEmpl(ds.Tables[0]);



            pageRowSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            for (int i = 0; i < total; i++)
            {
                emplAllList.Add(null);
            }
            for (int i = 0; i < pageRowSize; i++)
            {
                if (emplList.Count > i)
                {
                    emplAllList[((pageIndex - 1) * pageRowSize) + i] = emplList[i];
                }
            }

            return emplAllList;
        }

        /// <summary>
        /// 获取人员具体数据
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>修改或增加人员视图</returns>
        public ActionResult EmpContent(string empNo,string treeDeptNo,int pageIndex = 1)
        {
            ViewData["pageIndex"] = pageIndex;
            ViewData["treeDeptNo"] = treeDeptNo;
            Model.HREmpl emplModel = new Model.HREmpl();
            bool blempl = true;
            string deptPosition = string.Empty;
            string deptPositionHtml = string.Empty;
            if (string.IsNullOrEmpty(empNo))
            {
                emplModel.FSex = "男";
            }
            else
            {
                blempl = false;
                empNo = Fetch.estimateString(empNo, CheckGetEnum.Safety);
                BLL.HREmpl emplBll = new BLL.HREmpl();
                emplModel = emplBll.GetModel(GlobalConstant.ENTITYNO, empNo);
                if (null == emplModel)
                {
                    emplModel = new Model.HREmpl();
                    emplModel.FSex = "男";
                    blempl = true;
                }
                else //获取岗位相关数据
                {
                    BLL.HREmplPosition positionBll = new BLL.HREmplPosition();
                    DataSet ds = positionBll.GetEmplPositionInfo(emplModel.FEmplNo, GlobalConstant.ENTITYNO);
                    string no = string.Empty;
                    string name = string.Empty;
                    System.Text.StringBuilder str = new System.Text.StringBuilder();
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        no = row["FDeptNo"].ToString() + "%!^" + row["FPositionNo"].ToString();
                        name = row["FDeptName"].ToString() + ":" + row["FPositionName"].ToString();
                        deptPosition += no + "&";

                        str.Append("<input type='radio' name='positonNo' value='");
                        str.Append(no);
                        str.Append("'");
                        if (row["FIsMainPosition"].ToString() == "Y")
                        {
                            str.Append(" checked");
                        }
                        str.Append("/>");
                        str.Append(name);
                        str.Append("<br />");

                    }

                    deptPositionHtml = str.ToString();

                    if (deptPosition != string.Empty)
                    {
                        deptPosition = deptPosition.TrimEnd('&');
                    }

                }
            }

            if (null != emplModel.FPhoto && emplModel.FPhoto.Length > 0)
            {
                emplModel.FPhotoPath = Url.Content("~/Admin/Empl/PhotoShow?empNo=") + emplModel.FEmplNo;
            }
            else
            {
                emplModel.FPhotoPath = Url.Content("~/Content/images/Admin/defaultImg.jpg");
            }

            ViewData["blemp"] = blempl;

            ViewData["eduNoList"] = CommonCode.GetCodeList("HR_EDU");

            List<Model.SysBasicCodeName> codeList = new List<Model.SysBasicCodeName>();
            codeList.Add(new Model.SysBasicCodeName() { FCodeNo = "-1", FCodeName = "-----请选择------" });
            List<Model.SysBasicCodeName> tmpCodeList = CommonCode.GetCodeList("HR_DUTY");
            codeList.AddRange(tmpCodeList);
            ViewData["dutyNoList"] = codeList;
            ViewData["deptPosition"] = deptPosition;
            ViewData["hidDeptPositionHtml"] = deptPositionHtml;

            return View(emplModel);
        }


        /// <summary>
        /// 岗位树
        /// </summary>
        /// <param name="positons">岗位编号</param>
        /// <returns>绑定岗位树视图</returns>
        public ActionResult PositionTree(string positons)
        {
            BLL.HRDept deptBll = new BLL.HRDept();
            TreeModelList treeModelList = new TreeModelList();

            List<Model.HRDept> deptAllList = new List<Model.HRDept>();
            deptAllList = deptBll.GetListNoNameByEntityNo(GlobalConstant.ENTITYNO);

            BLL.HRPosition positionBll = new BLL.HRPosition();
            List<Model.HRPosition> positionAllList = positionBll.GetListByEntityNo(GlobalConstant.ENTITYNO);

            List<Model.HRDept> deptList = deptAllList.Where(c => c.FParentDeptNo == null).ToList();
            if (deptList.Count > 0)
            {
                foreach (Model.HRDept dept in deptList)
                {
                    TreeItemModel treeParentItemModel = new TreeItemModel(null)
                    {
                        Id = "%!^" + dept.FDeptNo,
                        Name = dept.FDeptName,
                        ImageUrl = Url.Content("~/Content/ControlImages/dept_Groups.png")
                    };

                    GetPostion(treeParentItemModel, dept.FDeptNo, positionAllList);
                    GetPositionChildDept(treeParentItemModel, deptAllList, dept.FDeptNo, positionAllList);

                    treeModelList.Add(treeParentItemModel);
                }
            }

            if (null == positons)
            {
                positons = string.Empty;
            }
            ViewData["deptPosition"] = positons;

            return View(treeModelList);

        }


        /// <summary>
        /// 递归岗位部门树
        /// </summary>
        /// <param name="treeParentItemModel">父级树节点</param>
        /// <param name="deptAllList">部门集合</param>
        /// <param name="preDeptNo">上级部门编号</param>
        /// <param name="positionAllList">岗位集合</param>
        public void GetPositionChildDept(TreeItemModel treeParentItemModel, List<Model.HRDept> deptAllList, string preDeptNo, List<Model.HRPosition> positionAllList)
        {
            List<Model.HRDept> deptList = deptAllList.Where(c => c.FParentDeptNo == preDeptNo).ToList();
            if (deptList.Count > 0)
            {
                foreach (Model.HRDept dept in deptList)
                {
                    TreeItemModel treeItemModel = new TreeItemModel(treeParentItemModel)
                    {
                        Id = "%!^" + dept.FDeptNo,
                        Name = dept.FDeptName,
                        ImageUrl = Url.Content("~/Content/ControlImages/dept_Groups.png")
                    };

                    GetPositionChildDept(treeItemModel, deptAllList, dept.FDeptNo, positionAllList);
                    GetPostion(treeItemModel, dept.FDeptNo, positionAllList);
                }
            }
        }

        /// <summary>
        /// 绑定岗位树岗位数据
        /// </summary>
        /// <param name="treeParentItemModel">父级树节点</param>
        /// <param name="deptNo">单位编号</param>
        /// <param name="positionAllList">岗位集合</param>
        public void GetPostion(TreeItemModel treeParentItemModel, string deptNo, List<Model.HRPosition> positionAllList)
        {
            List<Model.HRPosition> list = positionAllList.Where(c => c.FDeptNo == deptNo).ToList();
            foreach (Model.HRPosition positon in list)
            {
                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                {
                    Id = deptNo + "%!^" + positon.FPositionNo,
                    Name = positon.FPositionName,
                    ImageUrl = Url.Content("~/Content/ControlImages/mail_post_to.png")
                };
            }


        }

        /// <summary>
        /// 数据增加修改保存
        /// </summary>
        /// <param name="empl">人员信息MODEL</param>
        /// <returns>增加后显示视图</returns>
        public ActionResult Save(Model.HREmpl empl)
        {
            empl.FEntityNo = GlobalConstant.ENTITYNO;
            
            if (empl.FDutyNo == "-1")
            {
                empl.FDutyNo = null;
            }
            if (Fetch.Post("FIsCheck") != "U")
            {
                empl.FIsCheck = "Y";
            }
            else
            {
                empl.FIsCheck = "N";
            }


            if (Fetch.Post("FIsJoin") != "U")
            {
                empl.FIsJoin = "Y";
            }
            else
            {
                empl.FIsJoin = "N";
            }

            if (Fetch.Post("FIsAttendance") != "U")
            {
                empl.FIsAttendance = "Y";
            }
            else
            {
                empl.FIsAttendance = "N";
            }
            if (Fetch.Post("FIsAllowAddtionInsPlan") != "U")
            {
                empl.FIsAllowAddtionInsPlan = "Y";
            }
            else
            {
                empl.FIsAllowAddtionInsPlan = "N";
            }

            if (string.IsNullOrEmpty(empl.FEmplNo))
            {
                empl.FEmplNo = Fetch.Post("FEmplNo");
            }

            UploadedFile[] fileList = UploadControlExtension.GetUploadedFiles("photoUpload");
            if (null != fileList && fileList.Length > 0)
            {
                UploadedFile upload = fileList[0];
                if (upload.ContentLength > 0)
                {
                    empl.FPhoto = upload.FileBytes;
                }
            }

            //登录绑定IP地址
            empl.FLoginIPAddress = Fetch.Post("FLoginIPAddress");

            //获取岗位相关数据
            string deptPositionNos = Fetch.Post("hidDeptPosition");//岗位编号集合
            string mainPosition = Fetch.Post("positonNo");//主岗位

            List<Model.HREmplPosition> emplPositionList = new List<Model.HREmplPosition>();
            string[] deptPositionArray = deptPositionNos.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
            Model.HREmplPosition positionObj;
            string[] array;
            foreach (string deptPositon in deptPositionArray)
            {
                positionObj = new Model.HREmplPosition();
                array = deptPositon.Split(new string[] { "%!^" }, StringSplitOptions.RemoveEmptyEntries);
                positionObj.FDeptNo = array[0];
                positionObj.FEntityNo = GlobalConstant.ENTITYNO;
                positionObj.FIsMainPosition = deptPositon == mainPosition ? "Y" : "N";
                positionObj.FPositionNo = array[1];
                emplPositionList.Add(positionObj);
            }

            string type = "add";
            string saveType = Fetch.Post("hidSaveType");
            string hidEmplNo = Fetch.Post("hidEmplNo");
            if (hidEmplNo != string.Empty)
            {
                type = "edit";
            }

            ActionResult asctionResult = null;
            BLL.HREmpl emplBll = new BLL.HREmpl();
            try
            {
                if (type == "add")
                {
                    emplBll.AddEmplAndPosition(empl, emplPositionList);
                }
                else if (type == "edit")
                {
                    emplBll.UpdateEmplAndPosition(empl, emplPositionList);
                }

                if (saveType == "save")
                {
                    int pageIndex = Fetch.Post("hdPageIndex") == "" ? 1 : int.Parse(Fetch.Post("hdPageIndex").ToString());
                    string treeDeptNo = Fetch.Post("hdTreeDeptNo");
                    ViewData["hdRedirectURL"] = Url.Action("EmplList", "Empl", new
                    {
                        deptNo = treeDeptNo,
                        id = pageIndex
                    });
                }
                else if (saveType == "saveAdd")
                {
                    ViewData["hdRedirectURL"] = Url.Action("Index", "Empl", new { content = "Y" });
                }

                //ViewData["IsParent"] = "Y";
                asctionResult = View("SuccessMessagePage");

            }
            catch (Exception)
            {
                ViewData["message"] = "保存失败";

                ViewData["blemp"] = type == "add" ? true : false;

                ViewData["eduNoList"] = CommonCode.GetCodeList("HR_EDU");
                ViewData["dutyNoList"] = CommonCode.GetCodeList("HR_DUTY");

                ViewData["deptPosition"] = deptPositionNos;
                //ViewData["deptPositionHtml"] = Fetch.Post("hidDeptPositionHtml");
                asctionResult = View("EmpContent", empl);
            }

            return asctionResult;
        }


        /// <summary>
        /// 图片显示
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>图片显示视图</returns>
        public ActionResult PhotoShow(string empNo)
        {
            BLL.HREmpl emplBll = new BLL.HREmpl();
            byte[] photo = emplBll.GetPhoto(empNo, GlobalConstant.ENTITYNO);

            if (null == photo)
            {
                photo = new byte[0];
            }

            return new ImageResult()
            {
                byteStream = photo
            };
        }

        /// <summary>
        /// 判断人员编号是否已存在
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员是都存在</returns>
        [HttpPost]
        public string ExistsEmp(string empNo)
        {
            empNo = Fetch.estimateString(empNo, CheckGetEnum.Safety);
            string str = string.Empty;
            BLL.HREmpl empBll = new BLL.HREmpl();
            if (empBll.Exists(GlobalConstant.ENTITYNO, empNo))
            {
                str = "Y";
            }
            else
            {
                str = "N";
            }


            return str;
        }

        /// <summary>
        /// 判断正级岗位是否已绑定用户
        /// </summary>
        /// <param name="deptPositionNos">岗位编号</param>
        /// <param name="empNo">用户编号</param>
        /// <returns>返回是否绑定</returns>
        [HttpPost]
        public string ExistsMainPositon(string deptPositionNos, string empNo)
        {
            string str = string.Empty;

            string[] deptPositionArray = deptPositionNos.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
            Model.HREmplPosition positionObj;
            string deptNos = string.Empty;
            string positionNos = string.Empty;
            string[] array;
            foreach (string deptPositon in deptPositionArray)
            {
                positionObj = new Model.HREmplPosition();
                array = deptPositon.Split(new string[] { "%!^" }, StringSplitOptions.RemoveEmptyEntries);
                deptNos += "'" + Fetch.estimateString(array[0], CheckGetEnum.Safety) + "',";
                positionNos += "'" + Fetch.estimateString(array[1], CheckGetEnum.Safety) + "',";
            }

            if (deptNos != string.Empty)
            {
                deptNos = deptNos.TrimEnd(',');
            }

            if (positionNos != string.Empty)
            {
                positionNos = positionNos.TrimEnd(',');
            }

            BLL.HREmpl empBll = new BLL.HREmpl();
            try
            {
                int count = empBll.GetIsMainPositionCount(empNo, deptNos, positionNos, GlobalConstant.ENTITYNO);
                if (count > 0)
                {
                    str = "Y";
                }
                else
                {
                    str = "N";
                }
            }
            catch (Exception)
            {
                str = "error";
            }



            return str;
        }

        /// <summary>
        /// 删除人员数据
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>返回删除是否成功</returns>
        [HttpPost]
        public string DelEmp(string empNo)
        {
            empNo = Fetch.estimateString(empNo, CheckGetEnum.Safety);
            string str = string.Empty;
            BLL.HREmpl empBll = new BLL.HREmpl();
            try
            {
                empBll.DelEmlAndPosition(empNo, GlobalConstant.ENTITYNO);
                str = "ok";
            }
            catch (Exception)
            {
                str = "error";
            }
            return str;
        }

        /// <summary>
        /// 批量删除人员数据
        /// </summary>
        /// <param name="empNos">人员编号</param>
        /// <returns>返回批量删除是否成功</returns>
        [HttpPost]
        public string DeleteManyEmp(string empNos)
        {
            string str = string.Empty;
            string[] empArray = empNos.Split(new string[] { "%!^" }, StringSplitOptions.RemoveEmptyEntries);
            BLL.HREmpl empBll = new BLL.HREmpl();

            try
            {
                empBll.DelManyEmlAndPosition(empArray, GlobalConstant.ENTITYNO);
                str = "ok";
            }
            catch (Exception)
            {
                str = "error";
            }

            return str;
        }
        /// <summary>
        /// 个人信息修改
        /// </summary>
        /// <returns></returns>
        public ActionResult EmpSelfInfoEdit()
        {
            return EmpSelfInfoEdit(null, "");

        }
        private ActionResult EmpSelfInfoEdit(Model.HREmpl hrEmplModel, string jsAlert)
        {
            BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            string entityNo = GlobalConstant.ENTITYNO;
            if (hrEmplModel == null)
            {
                hrEmplModel = hrEmplBLL.GetModel(entityNo, emplNo);
            }
            return View("EmpSelfInfoEdit", hrEmplModel);
        }
        /// <summary>
        /// 人员同部门排序
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <returns>视图</returns>
        public ActionResult EmplSeq(string deptNo)
        {
            BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
            string entityNo = GlobalConstant.ENTITYNO;

            ViewData["docListJson"] = "";
            ViewData["focusId"] = deptNo;
            List<Model.HREmpl> hrEmplList = hrEmplBLL.GetDeptEmplList(entityNo, deptNo);
            ViewData["listJson"] = JsonConvert.SerializeObject(hrEmplList);

            return View();
        }
        /// <summary>
        /// 排序保存
        /// </summary>
        /// <param name="deptNos">排序的部门编号</param>
        /// <returns></returns>
        public string SaveRearrange(string emplNos)
        {
            string result = "FAILED";
            string errorMessage = "";
            string entityNo = GlobalConstant.ENTITYNO;
            string[] emplNoArray = emplNos.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
                hrEmplBLL.SeqEmplTop(emplNoArray, entityNo);
                result = "SUCCESS";
            }
            catch (Exception ee)
            {
                errorMessage = "排序保存失败" + ee.Message;
            }


            if (result == "FAILED")
            {
                if (errorMessage == "")
                {
                    errorMessage = "错误";
                }
                result += "|" + errorMessage;
            }
            return result;
        }

        /// <summary>
        /// 保存个人信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveEmpSelfInfo(Model.HREmpl hrEmplModel)
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            string entityNo = GlobalConstant.ENTITYNO;
            string errorMessage = "";
            ActionResult actionResult = null;
            Model.HREmpl newHREmplModel = new Model.HREmpl();
            newHREmplModel.FEmplNo = emplNo;
            newHREmplModel.FEntityNo = entityNo;
            newHREmplModel.FOfficeTel = hrEmplModel.FOfficeTel;
            newHREmplModel.FTelShortNo = hrEmplModel.FTelShortNo;
            newHREmplModel.FMobile = hrEmplModel.FMobile;
            newHREmplModel.FMobShortNo = hrEmplModel.FMobShortNo;
            newHREmplModel.FHomeTel = hrEmplModel.FHomeTel;
            newHREmplModel.FEMail = hrEmplModel.FEMail;
            newHREmplModel.FBirthday = hrEmplModel.FBirthday;
            try
            {
                BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
                hrEmplBLL.UpdateEmplBaseInfo(newHREmplModel);
                ViewData["RedirectURL"] = Url.Action("EmpSelfInfoEdit", "Empl");
                actionResult = View("SuccessMessagePage");
            }
            catch (Exception ee)
            {
                errorMessage = "信息修改失败" + ee.Message;
            }
            if (actionResult == null)
            {
                actionResult = EmpSelfInfoEdit(newHREmplModel, errorMessage);
            }
            return actionResult;
        }
    }
}
